<!--消防安全重点单位（重点部位）登记表 fire-->
<template>
    <Layout>
        <Form ref="queryForm" :model="dataToQuery" :label-width="120">
            <Row v-show="!switchFlag" class="query-form" >
                <Col span="8">
                    <FormItem label="企业名称：" prop="order">
                        <cascader-dom class="query-form-el" ref='queryOrgCascader' @setOrgInfo='setQueryCompanyName' :orgTree="true" :setCurrentName="{label:dataToQuery.companyName,value:dataToQuery.companyId}"></cascader-dom>
                    </FormItem>
                </Col>
                <Col span="8">
                    <FormItem label="登记时间：" prop="content" >
                        <DatePicker class="query-form-el" v-model="dataToQuery.dateRange" format="yyyy-MM-dd" type="daterange" placement="bottom-end" placeholder="请选择查询时间段"
                                    @on-change="onSelectQueryDateRange"></DatePicker>
                    </FormItem>
                </Col>
                <Col span="8">
                    <Button @click="switchQuery(true)" class="ivu-btn-switch" type="text">展开∨</Button>
                    <Button @click="reset" class="ivu-btn-reset"  >重置</Button>
                    <Button type="primary" class="ivu-btn-query"   icon="md-search"  @click="query">查询</Button>
                </Col>
            </Row>
            <Row v-show="switchFlag" class="query-form">
                <Col span="8">
                    <FormItem label="企业名称：" prop="order">
                        <cascader-dom class="query-form-el" ref='queryOrgCascader1' @setOrgInfo='setQueryCompanyName' :orgTree="true" :setCurrentName="{label:dataToQuery.companyName,value:dataToQuery.companyId}"></cascader-dom>
                    </FormItem>
                </Col>
                <Col span="8">
                    <FormItem label="登记时间：" prop="content" >
                        <DatePicker class="query-form-el" v-model="dataToQuery.dateRange" format="yyyy-MM-dd" type="daterange" placement="bottom-end" placeholder="请选择查询时间段"
                                    @on-change="onSelectQueryDateRange"></DatePicker>
                    </FormItem>
                </Col>
                <Col span="8">
                    <FormItem label="重点部位名称：" prop="highPriorName">
                        <Input v-model='dataToQuery.highPriorName' class="query-form-el"></Input>
                    </FormItem>
                </Col>
            </Row>
            <Row v-show="switchFlag" class="query-form">
                <Col span="8">
                    <FormItem label="主要设备设施：" prop="equipments">
                        <Input v-model='dataToQuery.equipments' class="query-form-el"></Input>
                    </FormItem>
                </Col>
                <Col span="8"></Col>
                <Col span="8" offset="8">
                    <Button @click="switchQuery(false)" class="ivu-btn-switch" type="text">收起∧</Button>
                    <Button @click="reset" class="ivu-btn-reset">重置</Button>
                    <Button class="ivu-btn-query" icon="md-search" @click="query">查询</Button>
                </Col>
            </Row>
            <Row class="query-form">
                <Col span="24">
                    <Button size="large"  class="ivu-btn-add" icon="md-add"  @click="addInfo">新增</Button>
                    <Button type="primary" class="ivu-btn-add"   icon="md-cloud-download"  @click="exportFormSubmit">导出</Button>
                </Col>
            </Row>
        </Form>
        <Table ref='table' :height="tableHeight"  no-data-text="没有查询到相关数据!" @on-selection-change = 'getSelectRows' :loading='pageStatus.loading'
               border :columns="columns1"  :data="dataTable" >
        </Table>
        <Row style="margin-right:10px;">
            <Col span="24" >
                <Page style="float: right" :total="pagedata.total" :page-size="pagedata.pageSize" @on-change="pageChange" @on-page-size-change="pageSizeChange" :page-size-opts="pageSizeArray" show-total show-sizer show-elevator />
            </Col>
        </Row>
        <Modal  title="消防安全重点单位（重点部位）登记表" :transfer=false :mask-closable="false" v-model="dialogShow" v-if="dataToView && dialogShow"  :width=800 :styles="{height:'658px'}"  class-name='limit-height-dialog'>
            <Row>
                <Col span="24">
                    <Form ref="dialogForm" :class="mode === 'view'?'modal-view-detail':'rpt-form'" :show-message="false"  :model="dataToView" :rules="mode === 'view'?{}:ruleCustom" :label-width="mode === 'view'?160:null" :label-position="mode === 'view'?'right':'top'">
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="23">
                                <FormItem label='企业名称：' prop='companyId'>
                                    <div v-if="mode === 'view'">{{dataToView.companyName}}</div>
                                    <cascader-dom v-else ref='orgCascader' @setOrgInfo='setCompanyId' @setOrgname="setCompanyName" :orgTree="true" :currentOrgId = "dataToView.companyId" :setCurrentName="{label:dataToView.companyName,value:dataToView.companyId}" ></cascader-dom>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label='所在地：' prop='companyAddress'>
                                    <div v-if="mode === 'view'">{{areaCodeToAreaName(dataToView.companyAddress)}}</div>
                                    <Cascader v-else :data="tempAreaTree" v-model="dataToView.companyAddressArr" change-on-select :transfer="true"
                                              :load-data="areaTreeLoadData" :render-format="labels=>labels.join('·')"  :clearable='false'
                                              @on-change="(value,selectedData)=>{$set(dataToView,'companyAddress',value.join(','))}"></Cascader>
                                </FormItem>
                            </Col>
                            <Col span="11">
                                <FormItem label='是否是消防安全重点单位：' prop='isHighPrior'>
                                    <div v-if="mode === 'view'">{{dataToView.isHighPrior && dataToView.isHighPrior == 1 ?  '是':'否'}}</div>
                                    <Select v-else class='query-form-el' v-model="dataToView.isHighPrior">
                                        <Option value="1">是</Option>
                                        <Option value="0">否</Option>
                                    </Select>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label='消防安全重点部位名称(只填写一个部位)：' prop='highPriorName'>
                                    <div v-if="mode === 'view'">{{dataToView.highPriorName}}</div>
                                    <Input v-else class='query-form-el' type='text' v-model='dataToView.highPriorName'></Input>
                                </FormItem>
                            </Col>
                            <Col span="11">
                                <FormItem label='主要设备设施：' prop='equipments'>
                                    <div v-if="mode === 'view'">{{dataToView.equipments}}</div>
                                    <Input v-else class='query-form-el' type='text' v-model='dataToView.equipments'></Input>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label='主机规格型号：' prop='equipmentModel'>
                                    <div v-if="mode === 'view'">{{dataToView.equipmentModel}}</div>
                                    <Input v-else class='query-form-el' type='text' v-model='dataToView.equipmentModel'></Input>
                                </FormItem>
                            </Col>
                            <Col span="11">
                                <FormItem label='填表人：' prop='registrant'>
                                    <div v-if="mode === 'view'">{{dataToView.createUserName}}</div>
                                    <Input v-else type='text' v-model='dataToView.registrant' readonly></Input>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="11">
                                <FormItem label='填表时间：' prop='registTime'>
                                    <div v-if="mode === 'view'">{{renderViewDate(dataToView.createDate)}}</div>
                                    <DatePicker v-else type="date" placeholder="请选择日期" class="query-form-el" v-model='dataToView.registTime' readonly></DatePicker>
                                </FormItem>
                            </Col>
                            <Col span="11">
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="23">
                                <FormItem label='配备的主要消防设备设施：' prop='fireEquipments'>
                                    <div v-if="mode === 'view'">{{dataToView.fireEquipments}}</div>
                                    <Input v-else class='query-form-el' type='text' v-model='dataToView.fireEquipments'></Input>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="23">
                                <FormItem label='消防设施、避雷设施检测情况：' prop='equipmentsExam'>
                                    <div v-if="mode === 'view'">{{dataToView.equipmentsExam}}</div>
                                    <Input v-else class='query-form-el' type='textarea' v-model='dataToView.equipmentsExam'></Input>
                                </FormItem>
                            </Col>
                        </Row>
                        <Row type="flex" justify="space-around" class="code-row-bg">
                            <Col span="23">
                                <FormItem label='备注：' prop='equipmentsExam'>
                                    <div v-if="mode === 'view'">{{dataToView.notes}}</div>
                                    <Input v-else class='query-form-el' type='textarea' v-model='dataToView.notes'></Input>
                                </FormItem>
                            </Col>
                        </Row>
                    </Form>
                </Col>
            </Row>
            <div slot="footer">
                <Button v-if="mode != 'view'" type="primary"  class='ivu-btn-save' @click="submit('dialogForm')" >确定</Button>
                <Button v-if="mode != 'view'" type="primary"  class='ivu-btn-cancel' @click="handleCancel" >取消</Button>
                <Button v-if="mode === 'view'" class='ivu-btn-save' @click="dialogShow=false">关闭</Button>
            </div>
        </Modal>
    </Layout>
</template>

<script>
  import {Api} from '@/api/index.js'
  import {formatDate} from '@/tools/index'
  import _deepclone from 'lodash/cloneDeep'
  import { mapState, mapGetters, mapActions } from 'vuex'
  var cascaderDom = () => import('@/components/cascader-dom.vue');
  import pageCommonFunction from '@/components/pageCommonFunction.js'
  export default {
    components:{
      cascaderDom
    },
    computed:{
        ...mapState('trhg', {
            areaMap: state => state.area.areaMap?state.area.areaMap:[],
            areaTreeMap: state => state.area.areaTreeMap?state.area.areaTreeMap:{},
        }),
    },
    data(){
      return{
        ...this.createCommonDataField(),
        columns1: [
          { title: '序号', width: 80, fixed: 'left', align: 'center', render: this.indexColumnsRender},
          // { key:'perfAssessNum',title: '绩效考核责任书编号',  align: 'center', width: 100  },
          { key:'companyName',title: '企业名称',  align: 'center', width: 240 },
          { key:'companyAddress',title: '所在地',  align: 'center', width: 120, render: this.renderCellArea  },
          { key:'isHighPrior',title: '是否消防安全重点单位',  align: 'center', width: 120, render: (h, params) => { return h('span', params.row.isHighPrior && params.row.isHighPrior == 1 ?  '是':'否')}},
          { key:'highPriorName',title: '消防安全重点部位名称',  align: 'center', width: 180  },
          { key:'equipments',title: '主要设备设施',  align: 'center', width: 120  },
          { key:'equipmentModel',title: '主机规格型号',  align: 'center', width: 200  },
          { key:'fireEquipments',title: '配备的主要消防设备设施',  align: 'left', width: 300, tooltip:true  },
          { key:'equipmentsExam',title: '消防设施、避雷设施检测情况',  align: 'left', width: 300, tooltip:true },
            { key:'createDate',title: '填表时间',  align: 'left', width: 120,  render: this.renderCellDate },
            { key:'notes',title: '备注',  align: 'center', width: 180},
            this.getActionColumns(),
        ],
        ruleCustom : {
          // perfAssessNum: [ { required: true, message: '请填写绩效考核责任书编号', trigger: 'change' } ],
            companyId: [ { required: true, message: '请填写企业名称', trigger: 'change' } ],
          companyAddress: [ { required: true, message: '请填写所在地', trigger: 'change' } ],
          // isHighPrior: [ { required: true, message: '请填写是否是消防安全重点单位', trigger: 'change' } ],
          // highPriorName: [ { required: true, message: '请填写消防安全重点部位名称', trigger: 'change' } ],
          // equipments: [ { required: true, message: '请填写主要设备设施', trigger: 'change' } ],
          // equipmentModel: [ { required: true, message: '请填写主机规格型号', trigger: 'change' } ],
          // fireEquipments: [ { required: true, message: '请填写配备的主要消防设备设施', trigger: 'change' } ],
          // equipmentsExam: [ { required: true, message: '请填写消防设施、避雷设施检测情况', trigger: 'change' } ],
          // notes: [ { required: true, message: '请填写备注', trigger: 'change' } ],
          // rptPeroid: [ { required: true, message: '请填写月份', trigger: 'change', type:'date' } ],
        },
        tableHeight:10,
        // api
        queryUrl:Api.querySafeRptFire,
        exportUrl:Api.exportSafeRptFire,
        deleteUrl:Api.deleteSafeRptFire,
        bthDeleteUrl:Api.batchDeleteSafeRptFire,
        getUrl:Api.getSafeRptFire,
        updateUrl:Api.updateSafeRptFire,
        saveUrl:Api.saveSafeRptFire,
      }
    },
    async mounted() {
      this.setTableHeight();
	  this.pageStatus.baseLoading = true
      await this.$store.dispatch('trhg/area/query', {scope:this}, { root: true })
	  this.pageStatus.baseLoading = false
      this.query();
        this.tempAreaTree = this.areaTreeMap['0']
    },
    methods:{
		...pageCommonFunction,

		createEmptyDataToAdd(){
            return {
                companyAddressArr:[]
            }
		},
        beforeEditDialogOpen(data) {
            if(data.row.companyAddress){
                data.row.companyAddressArr = data.row.companyAddress.split(',')
                data.row.companyAddressName = this.areaCodeToAreaName(data.row.companyAddress)
            }
        },
        async afterDataToViewInit(data) {
            if (data && data.companyAddress) {
                let companyAddressArr = data.companyAddress.split(',')
                this.tempAreaTree = []
                setTimeout(() => {
                    this.tempAreaTree = this.addressEditArr(this.areaTreeMap,companyAddressArr)
                }, 100)
            }
        },
		deleteData(params) {
			this.deleteDateAjax(params);
		},
		query() {
			this.queryAjax();
		},
		submit(name) {
            this.$set(this.dataToView,'companyAddress',this.dataToView.companyAddressArr.join(','))
			this.submitAjax(name);
		},

    },
    watch:{
    },

  }
</script>

<style lang='css' scoped>

    .rpt-form{}
    /deep/ .rpt-form .query-form-el{width:100%;}
    /deep/ .rpt-form .ivu-table-wrapper{overflow: visible;}
    /deep/ .rpt-form .ivu-table-wrapper .ivu-table{overflow: visible;}

</style>
